# _*_ coding: utf-8 _*_
'''
    该文件用于公司内部协议位置，无CRC校验版本
'''
import struct
import ctypes
import binascii


# 位置数据报文
def DCP_TX0x93Packet(data):
    leng = 38
    # 编码
    s1 = struct.Struct('>2BHB3B3BBBI')
    s2 = struct.Struct('dd')
    s3 = struct.Struct('>HHB')

    # 帧头,帧长度，信令ID，无线运营商，信号强度，温度，经纬度发送控制，卫星数量，达到一定强度的卫星数量，时间（大端）
    value1 = (0x7E,0x7F,leng,0x93,0x00, 0x00, 0x00,0x01, 0x00, 0x00,0x00, 0x00, int(data.sec))
    # 经度，纬度(小端)
    value2 = (data.longitude, data.latitude)
    # 速度，航向，定位状态
    value3 = (data.speed, data.direction, 0x01)
    prebuf = ctypes.create_string_buffer(s1.size + s2.size + s3.size)
    s1.pack_into(prebuf,0,*value1)
    s2.pack_into(prebuf,s1.size,*value2)
    s3.pack_into(prebuf, s1.size + s2.size, *value3)
    print('Pack bytes',bytes(prebuf))
    # print('Pack binascii:',binascii.hexlify(prebuf))
    return prebuf


if __name__ == '__main__':
    DCP_TX0x93Packet()